package org.springblade.common.utils.mq;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.thierrysquirrel.core.serializer.RocketSerializer;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;


/**
 * User: Jackey
 * Date: 2019/11/27
 * Time: 下午1:55
 * Description:
 */

@Component
public class JacksonSerializer implements RocketSerializer {
    private static ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public <T> byte[] serialize(T object) {

        System.out.println("================" + object.toString());

        System.out.println("====="+ object.toString().getBytes(StandardCharsets.UTF_8));
        System.out.println(object.toString().getBytes(StandardCharsets.UTF_8));
        return object.toString().getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public <T> T deSerialize(byte[] bytes, Class<T> clazz) {

        String string = new String(bytes, StandardCharsets.UTF_8);

        return (T)string;
    }
}
